package server

import (
	"github.com/akirakazu/go-simplejson"
	"io/ioutil"
	"net/http"
	"net/url"
)

const (
	PORT        int    = 443
	PROXY_URI   string = "conn.vlings.net"
	PROXY_PWD   string = "asdfghjkl;'"
	PROXY_ID    string = "initiative"
	LOG_FILE    string = "teleport.log"
	CCU_ID_FILE string = "/proc/ccu_ID"
	AUTH_URL    string = "http://42.121.122.147/ThinkPHP/sessions/get_session"
)

func (s *Server) cuAuth(id *json.Json, pwd string) bool {
	user, err := id.GetString("user")
	if err != nil {
		return false
	}
	// Whatever MAC address
	resp, err := http.PostForm(AUTH_URL, url.Values{"type": {"1"}, "mac": {"20:02:AF:11:1A:75"}, "username": {user}, "password": {pwd}})

	if err != nil {
		return false
	}
	defer resp.Body.Close()
	body, _ := ioutil.ReadAll(resp.Body)
	bodyJson, _ := json.NewJson([]byte(body))
	bodyMsg, err := bodyJson.GetString("Msg")
	if err != nil {
		return false
	}
	if bodyMsg != "ok" {
		return false
	}
	return true
}
